﻿using BBCore.Application.Interface;
using BBCore.Core.Models.Samples;
using BootstrapBlazor.Components;

namespace BBCore.Server.Components.Pages.Samples
{
    public partial class HYJ_Single_Table_CRUD
    {
        private Table<HYJ_Single_Table>? _table;
        private async Task<QueryData<HYJ_Single_Table>> OnQueryAsync(QueryPageOptions option) => await IDataQueryService.OnQueryAsync(option);
        private async Task<bool> OnDeleteAsync(IEnumerable<HYJ_Single_Table> items)
        {
            await freeSql.Delete<HYJ_Single_Table>().Where(items).ExecuteAffrowsAsync();
            return await Task.FromResult(true);
        }
        private async Task<bool> OnSaveAsync(HYJ_Single_Table item, ItemChangedType changedType)
        {
            if (changedType == ItemChangedType.Add)
            {
                await freeSql.Insert(item).ExecuteAffrowsAsync();
            }
            else if (changedType == ItemChangedType.Update)
            {
                await freeSql.Update<HYJ_Single_Table>().SetSource(item).ExecuteAffrowsAsync();
            }
            return await Task.FromResult(true);
        }
        private async Task tempDownload()
        {
            var filepath = await IExporterAndImporterService.TemplateDownloadAsync<HYJ_Single_Table>();
            await DownloadFromFileAsync(filepath);
            await ShowToastMessageAsync("模板下载",ToastCategory.Success);
        }
        private async Task DataImport(UploadFile uploadFile)
        {
            await Data_Import<HYJ_Single_Table>(uploadFile);
            await _table!.QueryAsync();
        }
    }
}
